<template>
  <a-drawer v-model:visible="visible" title="软件版本详情" :width="width >= 880 ? 880 : '100%'" :footer="false">
    <a-descriptions :column="2" size="large" class="general-description" bordered table-layout="fixed">
      <a-descriptions-item label="软件名称" :span="2">{{ dataDetail?.softwareName }}</a-descriptions-item>
      <a-descriptions-item label="软件版本名">{{ dataDetail?.versionName }}</a-descriptions-item>
      <a-descriptions-item label="软件版本号">{{ dataDetail?.versionCode }}</a-descriptions-item>
      <a-descriptions-item label="下载地址" :span="2">{{ dataDetail?.url }}</a-descriptions-item>
      <a-descriptions-item label="软件类型">
        <GiCellTag :value="dataDetail?.softwareType" :dict="software_type" />
      </a-descriptions-item>
      <a-descriptions-item label="状态">
        <GiCellStatus :status="dataDetail?.status" />
      </a-descriptions-item>
      <a-descriptions-item label="创建人">{{ dataDetail?.createUserString }}</a-descriptions-item>
      <a-descriptions-item label="创建时间">{{ dataDetail?.createTime }}</a-descriptions-item>
      <a-descriptions-item label="修改人">{{ dataDetail?.updateUserString }}</a-descriptions-item>
      <a-descriptions-item label="修改时间">{{ dataDetail?.updateTime }}</a-descriptions-item>
      <a-descriptions-item label="软件描述" :span="2">{{ dataDetail?.description }}</a-descriptions-item>
    </a-descriptions>
  </a-drawer>
</template>

<script lang="ts" setup>
import { useWindowSize } from '@vueuse/core'
import { type SoftwareDetailResp, getSoftware } from '@/apis/vending/software'
import { useDict } from '@/hooks/app'

const { width } = useWindowSize()

const { software_type } = useDict('software_type')

const visible = ref(false)
const dataId = ref('')
const dataDetail = ref<SoftwareDetailResp>()
// 查询详情
const getDataDetail = async () => {
  const res = await getSoftware(dataId.value)
  dataDetail.value = res.data
}

// 打开详情
const onDetail = async (id: string) => {
  dataId.value = id
  await getDataDetail()
  visible.value = true
}

defineExpose({ onDetail })
</script>

<style lang="scss" scoped></style>
